#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[n+10];
	for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
	int maxn = 0;
	int smx;
	int smi;
	int minn = 101;
	for(int i = 1,j = n;i<=n;i++,j--)
	{
		if(maxn<a[i])
		{
			maxn = a[i];
			smx = i;
		}
		if(minn>a[j])
		{
			minn = a[j];
			smi = j;
		}
	}
	if(smx<smi) printf("%d\n",smx-1+n-smi);
	else printf("%d\n",smx-1+n-smi-1);
}
